<?php

namespace app\adminapi\export;

use app\services\agent\AgentManageServices;
use Carbon\Carbon;

class AgentExport extends BaseExport
{
    protected $header = [
        '昵称', '手机号', '等级', '邀请方', '累计销售金额(元)', '累计佣金(元)', '账户余额', '加入时间'
    ];

    public function createData(array $where)
    {
        $list = app()->make(AgentManageServices::class)->agentSystemPage($where)['list'];

        $data = [];
        foreach ($list as $item) {
            $data[] = [
                $item['nickname'] ?? '',
                $item['phone'] ?? '',
                $item['level_name'] ?? '',
                $item['spread_name'] ?? '',
                $item['deal_unit_price'] ?? '',
                $item['brokerage_price'] ?? '',
                $item['now_money'] ?? '',
                $item['spread_time'] ? Carbon::parse($item['spread_time'])->format('Y-m-d H:i:s') : ''
            ];
        }

        return $data;
    }
}